#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
using namespace std;

class Solution {
public:
    bool isLetter(char ch) {
        if (ch >= 'a' && ch <= 'z' ||
            ch >= 'A' && ch <= 'Z') return true;
        return false;
    }
    string reverseOnlyLetters(string s) {
        int n = s.size();
        int left = 0, right = n - 1;
        while (left < right)
        {
            while (left < right && !isLetter(s[left])) left++;
            while (left < right && !isLetter(s[right])) right--;
            swap(s[left], s[right]);
            left++;
            right--;
        }
        return s;
    }
};

class Solution {
public:
    string minWindow(string s, string t) {
        int hash1[256] = { 0 }, hash2[256] = { 0 };
        int m = s.size(), n = t.size();
        int cnt = 0, len = 1000000, begin = 0;
        for (auto& e : t) hash2[e]++;

        for (int left = 0, right = 0; right < m; right++) {
            hash1[s[right]]++;
            if (hash1[s[right]] <= hash2[s[right]]) cnt++;
            while (cnt == n) {
                if (right - left + 1 < len) {
                    begin = left;
                    len = right - left + 1;
                }
                if (hash1[s[left]] <= hash2[s[left]]) cnt--;
                hash1[s[left++]]--;
            }
        }
        if (len == 1000000) return "";
        return s.substr(begin, len);
    }
};